//
//  YWProfileHeadView.m
//  maintain
//
//  Created by kyo on 16/12/5.
//  Copyright © 2016年 ewin. All rights reserved.
//

#import "YWProfileHeadView.h"
#import "YWMacro.h"
#import "UIColor+CustomColors.h"
#import "YWCommonTool.h"

#import "YWButton.h"

@interface YWProfileHeadView()
@property (weak, nonatomic) YWButton *workReminderButton;//提醒按钮
@property (weak, nonatomic) YWButton *grabBillButton;//抢单按钮
@property (weak, nonatomic) YWButton *monitorAlarmButton;//监控警报按钮
@property (weak, nonatomic) UILabel *workReminderLabel;
@property (weak, nonatomic) UILabel *grabBillLabel;
@property (weak, nonatomic) UILabel *monitorAlarmLabel;
@property (weak, nonatomic) UIView *line1;
@property (weak, nonatomic) UIView *line2;
@end
@implementation YWProfileHeadView


// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
//- (void)drawRect:(CGRect)rect {
//    // Drawing code
//}

- (void)setWorkReminderCount:(NSInteger)workReminderCount{
    _workReminderCount = workReminderCount>=0?workReminderCount:0;
    [self.workReminderButton setTitle:@(workReminderCount).stringValue forState:UIControlStateNormal];
}

- (void)setTroubleBillCount:(NSInteger)troubleBillCount{
    _troubleBillCount = troubleBillCount>=0?troubleBillCount:0;
    [self.grabBillButton setTitle:@(troubleBillCount).stringValue forState:UIControlStateNormal];
}

- (void)setMonitorAlarmCount:(NSInteger)monitorAlarmCount{
    _monitorAlarmCount = monitorAlarmCount>=0?monitorAlarmCount:0;
    [self.monitorAlarmButton setTitle:@(monitorAlarmCount).stringValue forState:UIControlStateNormal];
}


- (void)layoutSubviews{
    [super layoutSubviews];
    self.backgroundColor = [UIColor colorWithHex:@"353d40"];
    CGFloat gap = 20;
    CGFloat btnSize = (SCREEN_WIDTH - gap*6) / 3;
    self.workReminderButton.frame = CGRectMake(gap, gap/2, btnSize, btnSize);
    self.grabBillButton.frame = CGRectMake(gap*3+btnSize, gap/2, btnSize, btnSize);
    self.monitorAlarmButton.frame = CGRectMake(gap*5+btnSize*2, gap/2, btnSize, btnSize);
    
    self.workReminderLabel.frame  = CGRectMake(gap, CGRectGetMaxY(_workReminderButton.frame)+5, btnSize, 20);
    self.grabBillLabel.frame = CGRectMake(gap*3+btnSize, CGRectGetMaxY(_grabBillButton.frame)+5, btnSize, 20);
    self.monitorAlarmLabel.frame = CGRectMake(gap*5+btnSize*2, CGRectGetMaxY(_monitorAlarmButton.frame)+5, btnSize, 20);
    
    self.line1.frame = CGRectMake(CGRectGetMaxX(_workReminderLabel.frame)+gap, gap/2 + 5, 1, btnSize*3/5);
    self.line2.frame = CGRectMake(CGRectGetMaxX(_grabBillLabel.frame)+gap, gap/2 + 5, 1, btnSize*3/5);
}

- (YWButton *)workReminderButton{
    if (!_workReminderButton) {
        YWButton * button = [YWButton buttonWithType:UIButtonTypeCustom];
        [button setImage:[UIImage imageNamed:@"profile_workReminder"] forState:UIControlStateNormal];
        [button setTitle:@"0" forState:UIControlStateNormal];
        button.titleLabel.font = kContentFont;
        button.titleLabel.textAlignment = NSTextAlignmentCenter;
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(clickWorkReminderBtn:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:button];
        _workReminderButton = button;
        
        CGFloat gap = 20;
        CGFloat btnSize = (SCREEN_WIDTH - gap*6) / 3;
        CGFloat imageSize = 32;
        CGFloat btnInnerGap = (btnSize - imageSize - 20) / 3;
        button.imageRect = CGRectMake((btnSize-imageSize)/2, btnInnerGap, imageSize, imageSize);
        button.titleRect = CGRectMake(5, imageSize+(btnInnerGap*2), btnSize-10, 20);
    }
    return _workReminderButton;
}

- (YWButton *)grabBillButton{
    if (!_grabBillButton) {
        YWButton * button = [YWButton buttonWithType:UIButtonTypeCustom];
        [button setImage:[UIImage imageNamed:@"profile_grabTroubleBill"] forState:UIControlStateNormal];
        [button setTitle:@"0" forState:UIControlStateNormal];
        button.titleLabel.font = kContentFont;
        button.titleLabel.textAlignment = NSTextAlignmentCenter;
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(clickGrabBillButton:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:button];
        _grabBillButton = button;
        
        CGFloat gap = 20;
        CGFloat btnSize = (SCREEN_WIDTH - gap*6) / 3;
        CGFloat imageSize = 32;
        CGFloat btnInnerGap = (btnSize - imageSize - 20) / 3;
        button.imageRect = CGRectMake((btnSize-imageSize)/2, btnInnerGap, imageSize, imageSize);
        button.titleRect = CGRectMake(5, imageSize+(btnInnerGap*2), btnSize-10, 20);
    }
    return _grabBillButton;
}

- (YWButton *)monitorAlarmButton{
    if (!_monitorAlarmButton) {
        YWButton * button = [YWButton buttonWithType:UIButtonTypeCustom];
        [button setImage:[UIImage imageNamed:@"profile_monitorAlarm"] forState:UIControlStateNormal];
        [button setTitle:@"0" forState:UIControlStateNormal];
        button.titleLabel.font = kContentFont;
        button.titleLabel.textAlignment = NSTextAlignmentCenter;
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(clickMonitorAlarmButton:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:button];
        _monitorAlarmButton = button;
        
        CGFloat gap = 20;
        CGFloat btnSize = (SCREEN_WIDTH - gap*6) / 3;
        CGFloat imageSize = 32;
        CGFloat btnInnerGap = (btnSize - imageSize - 20) / 3;
        button.imageRect = CGRectMake((btnSize-imageSize)/2, btnInnerGap, imageSize, imageSize);
        button.titleRect = CGRectMake(5, imageSize+(btnInnerGap*2), btnSize-10, 20);
    }
    return _monitorAlarmButton;
}

- (UILabel *)workReminderLabel{
    if (!_workReminderLabel) {
        UILabel *label = [[UILabel alloc] init];
        label.font = kContentFont;
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor whiteColor];
        label.text = NSLocalizedString(@"remind", nil);
        [self addSubview:label];
        _workReminderLabel = label;
    }
    return _workReminderLabel;
}

- (UILabel *)grabBillLabel{
    if (!_grabBillLabel) {
        UILabel *label = [[UILabel alloc] init];
        label.font = kContentFont;
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor whiteColor];
        label.text = NSLocalizedString(@"grabTroubleBill", nil);
        [self addSubview:label];
        _grabBillLabel = label;
    }
    return _grabBillLabel;
}

- (UILabel *)monitorAlarmLabel{
    if (!_monitorAlarmLabel) {
        UILabel *label = [[UILabel alloc] init];
        label.font = kContentFont;
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor whiteColor];
        label.text = label.text = NSLocalizedString(@"monitorAlarm", nil);
        [self addSubview:label];
        _monitorAlarmLabel = label;
    }
    return _monitorAlarmLabel;
}

- (UIView *)line1{
    if (!_line1) {
        UIView* view = [[UIView alloc] init];
        [view setBackgroundColor:[UIColor customLineColor]];
        [self addSubview:view];
        _line1 = view;
    }
    return _line1;
}

- (UIView *)line2{
    if (!_line2) {
        UIView* view = [[UIView alloc] init];
        [view setBackgroundColor:[UIColor customLineColor]];
        [self addSubview:view];
        _line2 = view;
    }
    return _line2;
}

- (void)clickWorkReminderBtn:(id)sender{
    if ([self.delegate respondsToSelector:@selector(clickWorkRminderEvent:)]) {
        [self.delegate clickWorkRminderEvent:sender];
    }
}

- (void)clickGrabBillButton:(id)sender{
    if ([self.delegate respondsToSelector:@selector(clickGrabBillEvent:)]) {
        [self.delegate clickGrabBillEvent:sender];
    }
}

- (void)clickMonitorAlarmButton:(id)sender{
    if ([self.delegate respondsToSelector:@selector(clickMonitorAlarmEvent:)]) {
        [self.delegate clickMonitorAlarmEvent:sender];
    }
}

@end
